<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>WeakSet API</title>
</head>
<body>
  <script>
    const val1 = {id: 1},
          val2 = {id: 2},
          val3 = {id: 3};
    const ws1 = new WeakSet([val1, val2, val3]);

    console.log(ws1.has(val1)); // true
    console.log(ws1.has(val2)); // true
    console.log(ws1.has(val3)); // true
  </script>

  <script>
    const ws2 = new WeakSet([val1, "BADVAL", val3]);  // TypeError
    typeof ws2;  // ws2 is not defined
  </script>

  <script>
    // 原始值可以先包装为对象在用作值
    const stringVal = new String("val1");
    const ws3 = new WeakSet([stringVal]);
    console.log(ws3.has(stringVal));  // true
  </script>
</body>
</html>